#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.user;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;

import ${package}.user.bo.User;
import ${package}.user.dao.UserDAO;
import ${package}.user.dto.UserVO;

@Stateless
public class UserServiceImpl implements UserServiceLocal, UserServiceRemote
{
	private static final Logger log = Logger.getLogger(UserServiceImpl.class);

	@PersistenceContext
	private EntityManager manager;

	@Override
	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void createUser(UserVO userVO)
	{
		log.debug("Creating new user " + userVO.getName());

		UserDAO userDAO = new UserDAO(this.manager);

		User user = new User();
		user.setName(userVO.getName());

		userDAO.store(user);
	}

	@Override
	public List<UserVO> listAllUsers()
	{
		log.debug("Retrieving user list");

		UserDAO userDAO = new UserDAO(this.manager);

		List<User> users = userDAO.findAll();
		List<UserVO> usersVO = new ArrayList<UserVO>();
		if (users != null && users.size() > 0)
		{
			for (User user : users)
			{
				usersVO.add(UserParser.parseUser(user));
			}
		}

		return usersVO;
	}
}
